package com.lsp.kafkaconsumer.receiver;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class SimpleReceiver {

//    @KafkaListener(topics = "springboottopic",groupId = "springboottopic-group")
//    public void onMessage(String msg){
//
//        System.out.println("----收到消息单个："+msg+"----");
//    }
//
//    @KafkaListener(topics = "springboottopic",groupId = "springboottopic-group")
//    public void onMessage(List<String> msg){
//
//        System.out.println("----收到批量消息："+msg+"----");
//    }

    @KafkaListener(topics = "springboottopic",groupId = "springboottopic-group")
    public void processMessage(ConsumerRecord<?, ?> record, Acknowledgment ack) {
        try {
            System.out.printf("topic is %s, offset is %d,partition is %s, value is %s \n", record.topic(), record.offset(),record.partition(), record.value());
            // 手动提交offset
            ack.acknowledge();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
